<?php
	require_once("login/LoginHandler.php");
	require_once("fileUpload/FileUploadController.php");
	require_once("login/LoginView.php");
	require_once("login/loginController.php");
	require_once("register/registerController.php");
	require_once("members/memberListController.php");
	require_once('database/database.php');
	require_once('database/DBConfig.php');
	
	require_once('hash/hashConfig.php');
	require_once('hash/PasswordHash.php');
	
	class masterController {
				
		/**
		 * MasterController
		 * @return string html
		 * TODO: Lägg till länkar till Member och File list
		 */
		public function DoControll() {
			$fuc = new FileUploadController();
			$lc = new LoginController();
			$lw = new LoginView();
			$db = new Database();
			$dbc = new DBConfig();
			$rc = new RegisterController();
			$url = $this->GetUrlInfo();
			$mc = new MemberListController();
			$db->Connect($dbc);
			$lh = new LoginHandler($db);
			
			$body = "";
			
			$body .= $lc->DoControll($lh, $lw);
			
			if ($url == "register") {
				$body .= $rc->DoControll($lh, $db);
			}
			
			if ($url == "file") {
				$body .= $fuc->DoControll($lh->IsLoggedIn(), $lw);
			}
			
			if ($url == "members") {
				$body .= $mc->DoControll($lh, $db);
			}
			
			//TEMPORÄR JÄTTE FUL MENY--------------------------
			if ($lh->IsLoggedIn()) {
				$body .= "<a href='?controller=members'>Member list</a><br /><a href='?controller=file'>File list</a>";
			} else {
				$body .= "<a href='?controller=file'>File list</a>";
			}
			
			$db->Close();
			
			return $body;
		}
		
		/**
		 * @return string
		 */
		public function GetUrlInfo() {
			if (isset($_GET['controller'])) {
				return $_GET['controller'];
			}
		}
		
	}
?>